﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using MultWebApi.Models;
using MultWebApi.StoreWebApi.Auth;
using System.Security.Claims;

namespace MultWebApi.StoreWebApi.Controllers
{
    [ApiController]
    [Route("Product/")]
    [UserCheckControllerFilter]
    public class ProductController : Controller
    {
        [HttpPost("NewProduct")]
        [UserCheck(SystemFlag = 2, Action = "Inner")]
        public IActionResult NewProduct()
        {
            var rst = new DataResult();
            rst.ErrorCode = SysErrorCode.KSuccess;
            rst.Data = new { Id=1,Name="VMS-101",CreateDate=DateTime.Today.ToLongDateString() };
            rst.Message = SysErrorCode.GetErrorMessge(rst.ErrorCode);
            return new JsonResult(rst);
        }
        [AllowAnonymous]
        [HttpGet("GetUserName")]
        [UserCheck(SystemFlag = 2, Action = "Guest")]
        public IActionResult GetUserName()
        {
            string name =  HttpContext.User.Claims.FirstOrDefault(p => p.Type == ClaimTypes.Name)?.Value;
            var rst = new DataResult();
            rst.ErrorCode = SysErrorCode.KSuccess;
            rst.Data = new { Name = name };
            rst.Message = SysErrorCode.GetErrorMessge(rst.ErrorCode);
            return new JsonResult(rst);
        }
    }
}
